<?php
/* *
 * 支付宝当面付异步通知页面
 */
require_once("../../includes/fun.global.php");
/**
 * 写入测试数据
 */
require_once("config.php");
require_once("AlipayTradeService.php");

//计算得出通知验证结果
$alipaySevice = new AlipayTradeService($config);
$verify_result = $alipaySevice->check($_REQUEST);

if ($verify_result && !empty($conf['alipay_public_key']) && !empty($conf['merchant_private_key']) && (int)$conf['alipay_fpay_id'] == (int)$_REQUEST['app_id'] && $conf['pay_alipay'] == 3) {
    //商户订单号
    $out_trade_no = (int)$_QET['out_trade_no'];
    //支付宝交易号
    $trade_no = $_REQUEST['trade_no'];
    $srow = $DB->get_row("SELECT * FROM sky_pay WHERE `order`='{$out_trade_no}' limit 1");
    if ($_REQUEST['trade_status'] == 'TRADE_SUCCESS' && $srow['state'] == 2) {
        $acc = $DB->get_row("SELECT * FROM `sky_order` WHERE `order` = '$out_trade_no' ORDER BY `id` DESC LIMIT 1");
        if ($acc['order'] <> ''&&$acc) die('success');
        //付款完成后，支付系统发送该交易状态通知
        $_REQUEST['money'] = $_REQUEST['buyer_pay_amount'];
        \pay::success($_REQUEST, 2);
    } else echo "success";
} else {
    //验证失败
    echo "fail";
}
?>